// SETUP

#include intrographics.txt
#include ladyluckbiggraphics.txt

setdatapath("data/animations/jester/");

var jesterhumangraphics	= {
  idle: {
		animation: "data.json",
		pack: "pack.pck",
		loop: true
	},
	defiant: {
		animation: "defiant.json",
		pack: "pack.pck",
		loop: true
	}
}
var jesterhuman = addsprite("jesterhuman", 1, jesterhumangraphics);

setdatapath("data/graphics/cutscenes/jester/");

var jestergraphics = {
	idle: {
		animation: "jester_idle.json",
		pack: "jester.pck",
		loop: true
	},
	defiant_idle: {
		animation: "jester_defiant_idle.json",
		pack: "jester.pck",
		loop: true
	},
	transform: {
		animation: "jester_transform.json",
		pack: "jester.pck",
		speed: 2,
		loop: false
	}
}
var jester = addsprite("jester", 1, jestergraphics);

// HELPER FUNCTIONS	

function signanimate(sign) {
	var s = sign.show("turn");
	//s.onComplete(function() { resume(); sign.show("loop"); });
	//pause();
	while(!s.completed) {
		// do nothing
	}
	sign.show("loop");
}

function fadein_sprite(sprite, time) {
	return;
	sprite.alpha = 0.0;
	Actuate.tween(sprite, time, { alpha: 1.0 });
	wait(time);
}

function fadeout_sprite(sprite, time) {
	return;
	Actuate.tween(sprite, time, { alpha: 0.0 });
	wait(time);
}

var fade_time = 0.4;

// ACTORS
actor("Lady Luck", screenwidthmid + 800, 550, Col.YELLOW, CENTER, BOTTOM, "chat_ladyluck", "characters/misc/charicon_ladyluck");
actor("Jester", 2600, 600, 0xb496ec, RIGHT, TOP, "chat_jester", "characters/jester/charicon_jester");
// INTRO

play("music_cutscene_cheery");

changebackground("intro_sign");

sign.y = -screenheight;
ladyluck_sign.y = -screenheight;
sign.show("loop");
ladyluck_sign.show("idle");

Actuate.tween(sign, 2, { y: 0 }).ease(Expo.easeOut);
Actuate.tween(ladyluck_sign, 2, { y: 0 }).ease(Expo.easeOut);

wait(0.5);

fadein();
play("cutscene_audience");

wait(1.5);

ladyluck_sign.show("talking", true);
speak("Lady Luck", "... You.", "angry");
speak("Lady Luck", "After all these years. How could you? How *dare* you?", "angry");
ladyluck_sign.show("idle", true);

fadeout();
while(isfading()) {
	// do nothing
}

sign.hide();
ladyluck_sign.hide();

jesterhuman.x = 2640 - ((jesterhuman.getwidth("idle") * jesterhuman.scale) / 2);
jesterhuman.y = 370;
changebackground("intro_stage");
fadein();
jesterhuman.show("idle");

ladyluck_big.x = -screenwidth;
ladyluck_big.show("idle-confused");
Actuate.tween(ladyluck_big, 2, { x: 0 }).ease(Expo.easeOut);

actor("Jester", 2620 - 350, 200, Col.multiplylightness(Col.RED, 1.25), RIGHT, TOP, "chat_jester", "characters/misc/charicon_humanjester");
speak("Jester", "I’ve been down here so long!", "determined");
speak("Jester", "I just want to breathe fresh air and eat a|pizza and go on a rollercoaster and--", "determined");

ladyluck_big.show("talking-angry", true);
actor("Lady Luck", screenwidthmid + 240, screenheightmid - 240, Col.YELLOW, RIGHT, BOTTOM, "chat_ladyluck", "characters/misc/charicon_ladyluck");
speak("Lady Luck", "Silence! That was a rhetorical question, minion.", "scary");
ladyluck_big.show("idle-angry", true);

speak("Jester", "Plus I’m sick of being called a minion!");
speak("Jester", "Decades in the dungeon, working day and night,|and I’m still not even a sidekick?");

ladyluck_big.show("talking-sly", true);
actor("Lady Luck", screenwidthmid + 240, screenheightmid - 280, Col.YELLOW, RIGHT, BOTTOM, "chat_ladyluck", "characters/misc/charicon_ladyluck");
speak("Lady Luck", "So you'd prefer to try your hand as a CONTESTANT?", "sly");
ladyluck_big.show("idle-sly", true);

fadeout();
while(isfading()) {
	// do nothing
}
changebackground("intro_transform");
ladyluck_big.hide();
jesterhuman.hide();
fadein();

jester.x = screenwidth;
var transform = jester.show("transform");
Actuate.tween(jester, 2, { x: 0 }).ease(Expo.easeOut);

var marker_human = false;
var marker_dice = false;
while(true) {	
	if(!marker_human && transform.marker == "human") {
		marker_human = true;
		transform.paused = true;
    actor("Lady Luck", screenwidthmid + 800, 550, Col.YELLOW, CENTER, BOTTOM, "chat_ladyluck", "characters/misc/charicon_ladyluck");
    speak("Lady Luck", "Well, good luck with that!", "angry");
    play("transformintodice");
		transform.paused = false;
	} else if(!marker_dice && transform.marker == "dice") {
		marker_dice = true;
		transform.paused = true;
    actor("Lady Luck", screenwidthmid + 500, 550, Col.YELLOW, CENTER, BOTTOM, "chat_ladyluck", "characters/misc/charicon_ladyluck");
    speak("Lady Luck", "AND IN CASE IT WASN'T CLEAR, THAT WAS SARCASM.", "angry");
    speak("Lady Luck", "I HOPE YOU HAVE THE MOST MISERABLE EXPERIENCE OF ALL.", "angry");
    actor("Jester", screenwidthmid, screenheightmid - 540, Col.multiplylightness(Col.RED, 1.25), CENTER, BOTTOM, "chat_jester", "characters/jester/charicon_jester");
    speak("Jester", "It can’t be as miserable as working for you!", "determined");
    speak("Jester", "Let’s go!");
	  break;
	}
}


startgamefromcutscene();